//
//  TwoWayBindingViewController.swift
//  testRxSwift
//
//  Created by 火星人 on 2017/7/27.
//  Copyright © 2017年 火星人. All rights reserved.
//

import UIKit
import RxCocoa
import RxSwift

class TwoWayBindingViewController: BaseViewController {

    var disposed = DisposeBag()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        let textField = UITextField(frame: CGRect(x: 0, y: 80, width: self.view.width, height: 33))
        textField.backgroundColor = UIColor.lightGray.withAlphaComponent(0.2)
        
        self.view.addSubview(textField)
        
        let text = Variable("双向绑定")
        
        text.asObservable().subscribe { (eve) in
            print(eve)
        }.disposed(by: disposed)
        
        _  = textField.rx.textInput <-> text
        
        textField.rx.text
            .asObservable()
            .subscribe{
                print("textfield: \($0)")
            }
            .disposed(by: disposed)
        
        text.value = "hello"
        
    }
    


}

